﻿/*****************************************
 * File Name:   EvtControl.js
 * Author:      Chen Xin
 * Version:     1.0
 * Date:        2006-09-19
 * Description: 事件监听器
 *****************************************/

var EvtControl = new Array();

EvtControl.EventRouter = function(el, eventType) {
    this.lsnrs = new Array();
    this.el = el;
    el.eventRouter = this;
    el[eventType] = EvtControl.EventRouter.callback;
}

EvtControl.EventRouter.prototype.addListener = function(lsnr) {
    this.lsnrs.append(lsnr, true);
}

EvtControl.EventRouter.prototype.removeListener = function(lsnr) {
    this.lsnrs.remove(lsnr);
}
 
EvtControl.EventRouter.prototype.notify = function(e) {
    var lsnrs = this.lsnrs;
    for (var i = 0; i < lsnrs.length; i++) {
        var lsnr = lsnrs[i];
        lsnr.call(this, e);
    }
}

EvtControl.EventRouter.callback = function(event) {
    var e = event || window.event;
    var router = this.eventRouter;
    router.notify(e);
}